import { Plugin } from 'vite';
// @ts-ignore
import fs from 'fs';
// @ts-ignore
import path from 'path';
export function removeEmptyFiles(): Plugin {
	return {
		name : 'remove-empty-files',
		closeBundle() {
			const outDir: string = 'dist'; // 修改为你的输出目录
			recursion(outDir);
		}
	};
}
const recursion = (dir: string) => {
	fs.readdirSync(dir).forEach((file: any) => {
		const filePath: string = path.join(dir, file);
		const stat: fs.Stats = fs.lstatSync(filePath);
		if (fs.statSync(filePath).isDirectory()) {
			recursion(filePath);
		} else {
			if (stat.isFile() && '' === fs.readFileSync(filePath, 'utf-8').trim()) {
				fs.unlinkSync(filePath);
			}
		}
	});
};